﻿using Microsoft.EntityFrameworkCore;
using PHMEE.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;

namespace PHMEE.EnergyEfficiency
{
    /// <summary>
    /// 流量计模版数据仓储
    /// </summary>
    public class FlowmeterTemplateRepository : EfCoreRepository<PHMEEDbContext, FlowmeterTemplate, Guid>, IFlowmeterTemplateRepository
    {
        public FlowmeterTemplateRepository(IDbContextProvider<PHMEEDbContext> dbContextProvider) : base(dbContextProvider)
        {
        }
        /// <summary>
        /// 根据模版类型，获取数据
        /// </summary>
        /// <param name="mode"></param>
        /// <returns></returns>
        public async Task<List<FlowmeterTemplate>> GetTemplatesByModeAsync(FlowMeterModeEnum mode)
        {
            var dbSet = await GetDbSetAsync();
            return await dbSet
                .Where(template => template.TemplateMode == mode)
                .ToListAsync();
        }
        /// <summary>
        /// 获取所有流量计（即流量计所有子表名）
        /// </summary>
        /// <param name="mode"></param>
        /// <returns></returns>
        public async Task<List<string>> GetFlowmeterNames(FlowMeterModeEnum mode)
        {
            var dbContext = await GetDbContextAsync();
            return await dbContext.flowmeterTemplates
                .Where(temp => temp.TemplateMode == mode)
                .OrderBy(temp => temp.FlowmeterName)
                .Select(temp => temp.FlowmeterName)
                .ToListAsync();
        }
    }
}
